import {cacheTools} from 'nc-lightapp-front';
// import {addPkorgRefer} from '../../../public/functions/addCondition'
export default class headerAction {
    constructor(comp) {
        this.comp = comp;
    }

    /* 返回 */
    backToList = () => {
        const {action, props} = this.comp;
        const {dispatch} = props;
        dispatch({
            type: 'psninfoApprove/update',
            payload: {
                showMode: 'list-browse',
                selectedRowPk: []
            }
        });
        action.initAction.setTableData();
    };
    /* 组织选择 */
    searchChange = (val) => {
        const {props, action} = this.comp;
        const {dispatch} = props;
        dispatch({
            type: 'psninfoApprove/update',
            payload: {
                hrorgobj: val
            }
        });
        setTimeout(() => {
            action.initAction.setTableData();
        }, 100);
    };
    /* 按钮代理 */
    handleButtonAction = (props, evt) => {
        if (evt === 'search') {
            this.openFilterModal();
        }
        if (evt === 'multi-approve') {
            this.multiApprove();
        }
    };
    /* 查询modal */
    openFilterModal = () => {
        const {props} = this.comp;
        const {search, meta} = props;
        console.log(meta.getMeta())
        const _search_meta_ = meta.getMeta().search
        _search_meta_.items.forEach(item => {
            if (item.datatype === '204') {
                if (item.attrcode !== 'pk_checkuser') {
                    item.defaultUnitValue = props.psninfoApprove.hrorgobj
                }
            }
        })
        // addPkorgRefer(props, {
        // 	unitPks: props.psninfoApprove.hrorgobj.refpk || ''
        // })
        search.openAdvSearch('search', true);
    };

    /* 批量审核 */
    multiApprove = () => {
        const {action} = this.comp;
        action.cardAction.approveOpen();
    };
    /* 卡片翻页 */
    handlePageInfoChange = (prop, flag, status = 1) => {
        const {props, action} = this.comp;
        const {form, editTable, dispatch} = props;
        if (!flag) {
            form.EmptyAllFormValue('psninfoheadform');
            editTable.setTableData('handoverdetailgrid', []);
            return;
        }
        if (status === 3) {
            return false;
        }
        var allpks = cacheTools.get('allpks');
        if (!allpks.length) {
            form.EmptyAllFormValue('psninfoheadform');
            editTable.setTableData('handoverdetailgrid', []);
        } else {
            allpks.forEach((item, index) => {
                if (item === flag) {
                    dispatch({
                        type: 'psninfoApprove/update',
                        payload: {
                            selectedRowPk: [item]
                        }
                    });
                    setTimeout(() => {
                        action.cardAction.setDetailData(item, index);
                    }, 100);
                }
            });
        }
    };
}
